package com.sky.mapper;

import com.sky.dto.UserStatisticsDTO;
import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {

    /**
     * 根据openid查询用户
     * @param openid
     * @return
     */
    @Select("select * from user where openid = #{openid}")
    User getByOpenId(String openid);

    /**
     * 插入新用户数据
     * @param user
     */
    void insert(User user);

    /**
     * 用户统计
     * @param beginTime
     * @param endTime
     * @return
     */
    List<UserStatisticsDTO> getUserStatisticsByDateRange(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 获取开始时间的用户总数
     * @param begin
     * @return
     */
    @Select("select count(*) from user where DATE(create_time) = #{begin}")
    int getTotalByBegin(LocalDate begin);

    /**
     * 根据条件统计用户数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
